﻿<cfscript>
/** 
* ORM Book
* 
* @hint "Hibernate persistenter t_book. 教材选用目录" 
*
*/ 

component 
	displayname="public.service.orm.senate.Book" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="Book" 
	table="t_book"
	{

	property type="string" name="BookID" column="bid" fieldtype="id" generator="assigned" hint="教材号";

	property type="string" name="BookName" column="book_name" hint="书名";
	property type="string" name="Authors" column="book_authors" hint="教材作者";
	property type="string" name="Edition" column="book_edition" hint="版次";
	property type="string" name="ISBN" column="book_isbn" hint="ISBN书号";
	property type="string" name="Awards" column="book_awards" hint="教材获奖情况";

	property type="numeric" name="Prise" column="book_prise" hint="教材定价";
	property type="numeric" name="Stock" column="book_stock" hint="现有库存量";

	property type="string" name="PinYin" column="pyidx" hint="拼音首字母缩写检索";
	property type="string" name="FirstLetter" column="pyid" hint="拼音首字母";

	property name="Publisher" fieldtype="many-to-one" fkcolumn="pid" cfc="BookPublisher" hint="教材出版社";

	property name="CourseBooks" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="bid" cfc="CourseBook" hint="学期教材选用";
	property name="TeacherBooks" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="bid" cfc="TeacherBook" hint="学期教师参考用书";
	property name="BookStocks" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="bid" cfc="BookStock" hint="教材出入库变化情况";

	/**
	* @hint "自定义主键规则"
	*/
	public string function getNextID() output=false {
		
		var nextID = "1" & numberFormat(1, "0____");
		var checkArray = ORMExecuteQuery("select BookID from Book 
											where BookID like '1_____' 
											order by BookID desc", {}, { maxResults=1 });

		/* 
			主键生成规则 CHAR(6)
			
			1起头 5位为流水号 本序列代码代表本、专科教材系列
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = "1" & numberFormat((right(checkArray[1], 5) + 1), "0____");
			
		}

		return nextID;

	}

	
}

</cfscript>